<?php 
class baseDB
{
 // public $Id;
  
public function Insert()
{ 
  $st="INSERT INTO $this->mytablename ( " ; 
  $index=0;
   foreach($this as $key=>$value)
	 {   if($value!=$this->mytablename  )
	     {
	   	 if($index==0){$st.=$key;}else {$st.=','.$key;}
		 $index++;
		 }
	 }
  $st.=") VALUES  (";	 
	$index=0;
	 foreach($this as $key=>$value)
	 {
		 if($value!=$this->mytablename)
	     {
	   	 if($index==0){$st.="'".$value."'";}else {$st.=','."'".$value."'";}
		 $index++;
		 }
	 }
  $st.=")";
  $query=mysql_query($st)or die (mysql_error().' ' .$st);
    
  $this->Id=mysql_insert_id();	 
}
public function Update()
{ 
 $st="UPDATE $this->mytablename SET ";
 $index=0;
 	 foreach($this as $key=>$value)
	 { 
		 if($value!=$this->mytablename )
	     {
	   	 if($index==0){$st.=$key.'='."'".$value."'";}else {$st.=','.$key.'='."'".$value."'";}
		 $index++;
		}
	 }
	 $st.="WHERE Id=$this->Id";
	 
	 $query=mysql_query($st)or die (mysql_error().' ' .$st); 

	
}
public function GetById($id)
{ 
	$st="SELECT * FROM $this->mytablename WHERE Id=".$id;
   	$query=mysql_query($st)or die (mysql_error().' ' .$st);
	if(mysql_affected_rows()>0)
	 {
		 $row=mysql_fetch_assoc($query);
	   foreach($this as $key=>$value)
	    {
		  if($value!=$this->mytablename )
	        {
			$this->$key=$row[$key];
		    }
	   }
	   
	   return true;
		
		 
	 }
	else
	 {
		return 0; 
	 }
	
}
}

?>